package com.easyhuan.action;

import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.easyhuan.dao.GoodsUtil;
import com.easyhuan.pojo.Goods;
import com.easyhuan.pojo.Picture;
import com.easyhuan.util.HibernateUtil;
import com.opensymphony.xwork2.ActionSupport;

public class DetailAction extends ActionSupport {
	private Goods goods;
	private Set pictures;
	private List<Picture> picture;
	private Set comment;

	public Goods getGoods() {
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}


	public Set getPictures() {
		return pictures;
	}

	public void setPictures(Set pictures) {
		this.pictures = pictures;
	}

	public List<Picture> getPicture() {
		return picture;
	}

	public void setPicture(List<Picture> picture) {
		this.picture = picture;
	}

	public Set getComment() {
		return comment;
	}

	public void setComment(Set comment) {
		this.comment = comment;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		GoodsUtil util = new GoodsUtil();
		Session session = HibernateUtil.getHibernateSession();
		HttpServletRequest request = ServletActionContext.getRequest();
		try {
			String id = request.getParameter("id");
			this.goods = util.selectGoodsById(session, id);
			this.pictures = goods.getPictures();
			picture = (List<Picture>) pictures;
			this.comment = goods.getComments();
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
}
